﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Nop.Admin.Models.Directory;
using Nop.Admin.Models.Stores;
using Nop.Services.Directory;
using Nop.Web.Framework.Controllers;
using Telerik.Web.Mvc;

namespace Nop.Admin.Controllers
{
    [AdminAuthorize]
    public class RegionController : BaseNopController
    {
        private readonly IRegionService _regionService;

        public RegionController(IRegionService regionService)
        {
            _regionService = regionService;
        }

        // GET: Region
        public ActionResult Index()
        {
            return RedirectToAction("List");
        }

        // GET: region/list
        [HttpPost]
        public ActionResult List()
        {
            var regions = _regionService.GetAllRegions();
            return new JsonResult
            {
                Data = new SelectList(regions.Select(r=>new SelectListItem{ Text = r.Name, Value = r.Id.ToString(), Selected = false, Disabled = false}), "Value", "Text")
            };
        }
    }
}